package com.qfedu.tantu.controller;


import com.qfedu.tantu.dto.NewUserDto;
import com.qfedu.tantu.dto.UserFindDto;
import com.qfedu.tantu.dto.UserLoginDto;
import com.qfedu.tantu.service.intf.UserService;
import com.qfedu.tantu.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/api/user/")
@Api("用户登陆操作")
@CrossOrigin
public class UserController {
    @Resource
    private UserService service;
    @ApiOperation("手机号验证")
    @GetMapping("checkphone.do")
    public R check(String phone){
        return service.checkPhone(phone);
    }
    @ApiOperation("账号密码登录")
    @PostMapping("loginname.do")
    public R passLogin(@RequestBody UserLoginDto dto){
        return service.passLogin(dto);
    }
    @ApiOperation("手机号登录")
    @PostMapping("logincode.do")
    public R phoneLogin(@RequestBody UserLoginDto dto){
        return service.phoneLogin(dto);
    }
    @ApiOperation("修改密码")
    @PostMapping("findpass.do")
    public R passUpdate(@RequestBody UserFindDto dto){
        return service.passUpdate(dto);
    }
    @ApiOperation("注销")
    @GetMapping("loginout.do")
    public R liginOut(HttpServletRequest request){
        //传递token 采取请求消息头
        return service.loginOut(request.getIntHeader("bbtoken"));
    }
    @ApiOperation("注册手机号验证")
    @GetMapping("checkregister.do")
    public R checkRegister(String phone){
        return service.checkRegister(phone);
    }

    //gsz·····
    @ApiOperation("查询图像")
    @GetMapping("findimg.do")
    public R findImg(String name){
        R r=service.queryImg(name);

        System.out.println(r+"gsz");
        return r;
    }
    //新用户注册
    //新用户注测
    @ApiOperation("注册新用户")
    @PostMapping("register.do")
    public R save(@RequestBody NewUserDto dto){
        return service.register(dto);
    }
}
